package dao.jpa;

import java.util.List;

import metiers.Film;

public class DAOFilmJPA implements DAOFilm {
	
	static private DAOFilmJPA instance = null;
	
	private DAOFilmJPA() {
	}
	
	static public DAOFilm getInstance() {
		 	if (instance == null)
				instance = new DAOFilmJPA();
		 	
		 	return instance;
	}
	

	@Override
	public List<Film> loadAll() {
		return DAOJPA.getManager().createQuery("SELECT f FROM Film f",Film.class).getResultList();
	}

	@Override
	public void save(Film film) {
		DAOJPA.getManager().persist(film);
	 	DAOJPA.commit();
	}

	@Override
	public Film get(int id) {
		Film f = DAOJPA.getManager().find(Film.class, id);
		return f;
	}
 
}
